<?php
class Artistas extends ActiveRecord {
    /*public function lista($pais,$page){
        return $this->paginate("conditions: idPais = '$pais'","order: visto DESC","per_page: 10", "page: $page");
    }*/
    public function lista($pais,$page){
        $query  = "SELECT artistas.*,GROUP_CONCAT(DISTINCT genero.genero) AS generos,GROUP_CONCAT(DISTINCT genero.id) as generosId ";
        $query .= "FROM artistas,artistaGenero,genero ";
        $query .= "WHERE artistas.id=idArtista AND idGenero = genero.id AND artistas.pais_id='".$pais."' ";
        $query .= "GROUP BY artistas.autor ";
        $query .= "ORDER BY visto  desc ";
        return $this->paginate_by_sql($query,"page: $page", 'per_page: 10');
    }
    public function listaGenero($idGenero,$page){
        return $this->paginate_by_sql('SELECT * FROM artistas,artistaGenero WHERE artistaGenero.idGenero="' . $idGenero . '" AND artistaGenero.idArtista=artistas.id ORDER BY visto DESC',"page: $page", 'per_page: 10');
    }
    public function masVistos(){
        return $this->find("order: visto desc","limit: 10");
    }
    public function verInfo($ter){
        $query  = "SELECT artistas.*,GROUP_CONCAT(DISTINCT genero.genero) AS generos,GROUP_CONCAT(DISTINCT genero.id) as generosId ";
        $query .= "FROM artistas,artistaGenero,genero ";
        $query .= 'WHERE artistas.id=idArtista AND idGenero = genero.id AND artistas.autor="'.$ter.'" ';
        $query .= "GROUP BY artistas.autor ";
        $query .= "ORDER BY visto  desc ";
        $autor = $this->find_by_sql($query);
        //$autor = $this->find_first("conditions: autor = '$ter'");
        if($autor->autor)
            return $autor;
        else
            return false;
    }
}
?>
